package cdms.web;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.springframework.jdbc.core.JdbcTemplate;

import cdms.config.DataConfig;

/**
 * 计数标签 统计当前在线的配送员数量
 * 
 * @author ChenJing
 * @version 1.0
 *
 */
public class CounterTag extends SimpleTagSupport {

	DataConfig dataConfig = new DataConfig();

	JdbcTemplate jdbc = dataConfig.jdbcTemplate(dataConfig.dataSource());

	@Override
	public void doTag() throws JspException {
		try {
			JspWriter out = getJspContext().getOut();
			out.print(getCounter());
		} catch (java.io.IOException e) {
			throw new JspTagException(e.getMessage());
		}
	}

	public int getCounter() {
		return (int) jdbc.queryForLong("select count(id) from sender where isdeleted = false and isOnline = true");
	}
}
